#include <iostream>
#include <cmath>

#define max 1024
using namespace std;

int main() {
    int n;  //n个学生
    scanf("%d", &n);
    int grades[3][max];  //行=3表示语文、数学、英语成绩，列表示学生
    int count = 0;
    for (int i = 1; i <= n; ++i) {
        scanf("%d %d %d", &grades[0][i], &grades[1][i], &grades[2][i]);
    }
    for (int i = 1; i <= n - 1; ++i) { //从第一个学生遍历到倒数第二个学生
        for (int j = i + 1; j <= n; ++j) { //从第二个学生遍历到最后一个学生
            if (abs(grades[0][i] - grades[0][j]) <= 5 && abs(grades[1][i] - grades[1][j]) <= 5 &&
                abs(grades[2][i] - grades[2][j]) <= 5 &&
                abs(grades[0][i] + grades[1][i] + grades[2][i] - grades[0][j] - grades[1][j] - grades[2][j]) <= 10) {
                count++;
            }
        }
    }
    printf("%d", count);
    return 0;
}
